<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />


<meta name="author" content="Yiying Wang" />

<meta name="date" content="2017-03-15" />

<title>Basic Plots 02 - Bar/Column</title>

<script src="libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="libs/navigation-1.1/tabsets.js"></script>
<script src="libs/htmlwidgets-0.8/htmlwidgets.js"></script>
<script src="libs/echarts-2.2.7/echarts-all.js"></script>
<script src="libs/charts-ext-2.2.7/main.js"></script>
<script src="libs/charts-ext-2.2.7/BMap.js"></script>
<script src="libs/echarts-binding-0.2/echarts.js"></script>


<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
  pre:not([class]) {
    background-color: white;
  }
</style>


<style type="text/css">
h1 {
  font-size: 34px;
}
h1.title {
  font-size: 38px;
}
h2 {
  font-size: 30px;
}
h3 {
  font-size: 24px;
}
h4 {
  font-size: 18px;
}
h5 {
  font-size: 16px;
}
h6 {
  font-size: 12px;
}
.table th:not([align]) {
  text-align: left;
}
</style>

<link rel="stylesheet" href="/home/madlogos/R/x86_64-pc-linux-gnu-library/3.3/knitr/misc/vignette.css" type="text/css" />

</head>

<body>

<style type = "text/css">
.main-container {
  max-width: 940px;
  margin-left: auto;
  margin-right: auto;
}
code {
  color: inherit;
  background-color: rgba(0, 0, 0, 0.04);
}
img {
  max-width:100%;
  height: auto;
}
.tabbed-pane {
  padding-top: 12px;
}
button.code-folding-btn:focus {
  outline: none;
}
</style>



<div class="container-fluid main-container">

<!-- tabsets -->
<script>
$(document).ready(function () {
  window.buildTabsets("TOC");
});
</script>

<!-- code folding -->






<div class="fluid-row" id="header">



<h1 class="title toc-ignore">Basic Plots 02 - Bar/Column</h1>
<h4 class="author"><em>Yiying Wang</em></h4>
<h4 class="date"><em>2017-03-15</em></h4>

</div>

<div id="TOC">
<ul>
<li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a></li>
<li><a href="#function-call"><span class="toc-section-number">2</span> Function Call</a></li>
<li><a href="#showcase"><span class="toc-section-number">3</span> Showcase</a><ul>
<li><a href="#data-preparation"><span class="toc-section-number">3.1</span> Data Preparation</a></li>
<li><a href="#horizontal-bar-chart"><span class="toc-section-number">3.2</span> Horizontal Bar Chart</a><ul>
<li><a href="#singular-series"><span class="toc-section-number">3.2.1</span> Singular Series</a></li>
<li><a href="#multiple-series"><span class="toc-section-number">3.2.2</span> Multiple Series</a></li>
<li><a href="#stacked-horizontal-bar-chart"><span class="toc-section-number">3.2.3</span> Stacked Horizontal Bar Chart</a></li>
<li><a href="#tornado-chart"><span class="toc-section-number">3.2.4</span> Tornado Chart</a></li>
<li><a href="#population-pyramid"><span class="toc-section-number">3.2.5</span> Population Pyramid</a></li>
<li><a href="#bar-chart-with-timeline"><span class="toc-section-number">3.2.6</span> Bar Chart with Timeline</a></li>
</ul></li>
<li><a href="#vertical-bar-column-chart"><span class="toc-section-number">3.3</span> Vertical Bar (Column) Chart</a><ul>
<li><a href="#tiled-vertical-bar-column-chart"><span class="toc-section-number">3.3.1</span> Tiled Vertical Bar (Column) Chart</a></li>
<li><a href="#stacked-vertical-bar-column-chart"><span class="toc-section-number">3.3.2</span> Stacked Vertical Bar (Column) Chart</a></li>
</ul></li>
<li><a href="#histogram"><span class="toc-section-number">3.4</span> Histogram</a><ul>
<li><a href="#stat-by-frequency"><span class="toc-section-number">3.4.1</span> Stat by Frequency</a></li>
<li><a href="#stat-by-density"><span class="toc-section-number">3.4.2</span> Stat by Density</a></li>
</ul></li>
</ul></li>
<li><a href="#futher-setup"><span class="toc-section-number">4</span> Futher Setup</a></li>
</ul>
</div>

<p>First, you should load <code>recharts</code>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(recharts)</code></pre></div>
<div id="introduction" class="section level1">
<h1><span class="header-section-number">1</span> Introduction</h1>
<p>Bar plot includes 3 basic types:</p>
<ul>
<li>horizontal bar: bar|hbar</li>
<li>vertical bar: column|vbar</li>
<li>histogram: histogram|hist</li>
</ul>
<table id="intro">
<tr>
<td>
<div id="htmlwidget-df37f58fedbf2633d66e" style="width:400px;height:300px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-df37f58fedbf2633d66e">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"right","y":"center","orient":"vertical"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"theme":"infographic","title":{"text":"Titanic: Survival by Cabin Class","subtext":"hbar","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</td>
<td>
<div id="htmlwidget-e085e12cd1c6bb892b43" style="width:400px;height:300px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-e085e12cd1c6bb892b43">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"right","y":"center","orient":"vertical"},"yAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"theme":"roma","title":{"text":"Titanic: Outcome by Cabin Class","subtext":"column","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</td>
</tr>
<tr>
<td>
<div id="htmlwidget-1d6b5e7ccc54cedd64e2" style="width:400px;height:300px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-1d6b5e7ccc54cedd64e2">{"x":{"series":[{"type":"bar","data":[[2.1,4],[2.3,7],[2.5,13],[2.7,23],[2.9,36],[3.1,24],[3.3,18],[3.5,10],[3.7,9],[3.9,3],[4.1,2],[4.3,1]],"barGap":"1%","barMaxWidth":63,"barWidth":17.6923076923077}],"yAxis":[{"type":"value","show":true,"position":"left","name":"Freq","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"value","show":true,"position":"bottom","name":"Sepal.Width","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"legend":{"show":true,"data":[],"x":"right","y":"center","orient":"vertical"},"theme":"macarons","title":{"text":"Iris Sepal Width","subtext":"histogram","x":"center","y":"bottom","orient":"horizontal"}},"evals":[],"jsHooks":[]}</script>
</td>
<td>
</td>
</tr>
</table>
<p>The keys are:</p>
<ul>
<li>character <code>x</code> and numeric <code>y</code></li>
<li>each combination level of <code>x</code> (and <code>series</code>) can only have one <code>y</code> data point</li>
<li>Tiled and stacked bar/column charts can shift from one to another by clicking type shift buttons in the toolbox widget.</li>
</ul>
</div>
<div id="function-call" class="section level1">
<h1><span class="header-section-number">2</span> Function Call</h1>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(data, x, &lt;y&gt;, &lt;series&gt;, &lt;t&gt;, &lt;type&gt;, &lt;subtype&gt;)</code></pre></div>
<table>
<colgroup>
<col width="12%" />
<col width="87%" />
</colgroup>
<thead>
<tr class="header">
<th>Arg</th>
<th>Requirement</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p><strong>data</strong></p></td>
<td><p>source data in the form of data.frame</p></td>
</tr>
<tr class="even">
<td><p><strong>x</strong></p></td>
<td><ul>
<li>character independent variable. Other type will be coerced to factors. Only the first one is accepted if multiple variables are provided.</li>
<li>numeric variable and <code>y</code> is omitted, in which case comes up with a histogram.</li>
</ul></td>
</tr>
<tr class="odd">
<td><p>y</p></td>
<td><ul>
<li>numeric dependent variable. Only the first one is accepted if multiple variables are provided.</li>
<li>If y is omitted, and x is numeric, a histogram will be displayed.</li>
</ul></td>
</tr>
<tr class="even">
<td><p>series</p></td>
<td><p>data series variable which will be coerced to factors. Only the first one is accepted if multiple variables are provided.</p></td>
</tr>
<tr class="odd">
<td><p>t</p></td>
<td><p>timeline variable which will be coerced to factors. Only the first one is accepted if multiple variables are provided.</p></td>
</tr>
<tr class="even">
<td><p>type</p></td>
<td><ul>
<li><code>x</code> is character and <code>y</code> is numeric, or ‘x’ is numeric and ‘y’ is omitted, you can omit ‘type’ or assign it ‘auto’.</li>
<li>You can also assign it ‘bar’, ‘hbar’, ‘vbar’, ‘column’, ‘hist’, ‘histogram’.</li>
</ul></td>
</tr>
<tr class="odd">
<td><p>subtype</p></td>
<td><ul>
<li>bar/column: c(‘stack’)
<ul>
<li>stack: stacked series</li>
</ul></li>
<li>hist: c(‘count’, ‘freq’, ‘density’)
<ul>
<li>count/freq: stat by freq</li>
<li>denstiy: stat by density</li>
</ul></li>
</ul></td>
</tr>
</tbody>
</table>
</div>
<div id="showcase" class="section level1">
<h1><span class="header-section-number">3</span> Showcase</h1>
<div id="data-preparation" class="section level2">
<h2><span class="header-section-number">3.1</span> Data Preparation</h2>
<p>Let’s look into <code>Titanic</code> dataset embeded in the package <code>datasets</code>. The survival count by cabin class is shown as below:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">titanic &lt;-<span class="st"> </span>data.table::<span class="kw">melt</span>(<span class="kw">apply</span>(Titanic, <span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">4</span>), sum))
<span class="kw">names</span>(titanic) &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="st">&#39;Class&#39;</span>, <span class="st">&#39;Survived&#39;</span>, <span class="st">&#39;Count&#39;</span>)
knitr::<span class="kw">kable</span>(titanic)</code></pre></div>
<table>
<thead>
<tr class="header">
<th align="left">Class</th>
<th align="left">Survived</th>
<th align="right">Count</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">1st</td>
<td align="left">No</td>
<td align="right">122</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">No</td>
<td align="right">167</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">No</td>
<td align="right">528</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">No</td>
<td align="right">673</td>
</tr>
<tr class="odd">
<td align="left">1st</td>
<td align="left">Yes</td>
<td align="right">203</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">Yes</td>
<td align="right">118</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">Yes</td>
<td align="right">178</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">Yes</td>
<td align="right">212</td>
</tr>
</tbody>
</table>
</div>
<div id="horizontal-bar-chart" class="section level2">
<h2><span class="header-section-number">3.2</span> Horizontal Bar Chart</h2>
<div id="singular-series" class="section level3">
<h3><span class="header-section-number">3.2.1</span> Singular Series</h3>
<p><code>type</code> could be ‘hbar’, ‘bar’ or ‘auto’.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic[titanic$Survived==<span class="st">&#39;Yes&#39;</span>,], Class, Count) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&#39;Titanic: N Survival by Cabin Class&#39;</span>)</code></pre></div>
<div id="htmlwidget-28589b852c0d634cd873" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-28589b852c0d634cd873">{"x":{"series":[{"type":"bar","data":[203,118,178,212]}],"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"legend":{"show":true,"data":[],"x":"left","y":"top","orient":"horizontal"},"title":{"text":"Titanic: N Survival by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="multiple-series" class="section level3">
<h3><span class="header-section-number">3.2.2</span> Multiple Series</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic, Class, Count, Survived) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&#39;Titanic: Survival Outcome by Cabin Class&#39;</span>)</code></pre></div>
<div id="htmlwidget-34f38dc49f061aadf5b6" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-34f38dc49f061aadf5b6">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="stacked-horizontal-bar-chart" class="section level3">
<h3><span class="header-section-number">3.2.3</span> Stacked Horizontal Bar Chart</h3>
<p>Compared to hbar, you just set <code>subtype</code> ‘stack’.</p>
<p>Grammar for singular and multiple series are similar to legacy hbar chart.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic, Class, Count, Survived, <span class="dt">type=</span><span class="st">&#39;hbar&#39;</span>, <span class="dt">subtype=</span><span class="st">&#39;stack&#39;</span>) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&#39;Titanic: Survival Outcome by Cabin Class&#39;</span>) </code></pre></div>
<div id="htmlwidget-a87ebca1a9fa67271f7f" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-a87ebca1a9fa67271f7f">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673],"stack":"Group"},{"name":"Yes","type":"bar","data":[203,118,178,212],"stack":"Group"}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="tornado-chart" class="section level3">
<h3><span class="header-section-number">3.2.4</span> Tornado Chart</h3>
<p>Tornado chart is a special case. The keys are:</p>
<ul>
<li>An all-positive series and an all-negative series</li>
<li>Tiled rather than stacked</li>
</ul>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">titanic_tc &lt;-<span class="st"> </span>titanic
titanic_tc$Count[titanic_tc$Survived==<span class="st">&#39;No&#39;</span>] &lt;-<span class="st"> </span>
<span class="st">    </span>-<span class="st"> </span>titanic_tc$Count[titanic_tc$Survived==<span class="st">&#39;No&#39;</span>]
g &lt;-<span class="st"> </span><span class="kw">echartr</span>(titanic_tc, Class, Count, Survived, <span class="dt">type=</span><span class="st">&#39;hbar&#39;</span>) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&quot;Titanic: Survival Outcome by Cabin Class&quot;</span>)
g</code></pre></div>
<div id="htmlwidget-bcefa7cc82a578426803" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-bcefa7cc82a578426803">{"x":{"series":[{"name":"No","type":"bar","data":[-122,-167,-528,-673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
<p>Of course we need to adjust the axis a little bit as well. Y-axis should intersect x-axis at zero and the label of x-axis should be absolute values (a little bit complex, you’d better know a little bit JaveScript).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">g %&gt;%<span class="st"> </span><span class="kw">setYAxis</span>(<span class="dt">axisLine=</span><span class="kw">list</span>(<span class="dt">onZero=</span><span class="ot">TRUE</span>)) %&gt;%<span class="st"> </span>
<span class="st">    </span><span class="kw">setXAxis</span>(<span class="dt">axisLabel=</span><span class="kw">list</span>(
        <span class="dt">formatter=</span><span class="kw">JS</span>(<span class="st">&#39;function (value) {return Math.abs(value);}&#39;</span>)
    ))</code></pre></div>
<div id="htmlwidget-251c3eea44a05907c916" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-251c3eea44a05907c916">{"x":{"series":[{"name":"No","type":"bar","data":[-122,-167,-528,-673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":true},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true,"formatter":"function (value) {return Math.abs(value);}"},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["xAxis.0.axisLabel.formatter","tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="population-pyramid" class="section level3">
<h3><span class="header-section-number">3.2.5</span> Population Pyramid</h3>
<p>So when you apply ‘hbar’ to <code>type</code> and ‘stack’ to <code>subtype</code>, you yield a ‘population pyramid’ as usually used in sociology.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic_tc, Class, Count, Survived, <span class="dt">type=</span><span class="st">&#39;hbar&#39;</span>, <span class="dt">subtype=</span><span class="st">&#39;stack&#39;</span>) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&quot;Titanic: Survival Outcome by Cabin Class&quot;</span>) %&gt;%
<span class="st">    </span><span class="kw">setYAxis</span>(<span class="dt">axisLine=</span><span class="kw">list</span>(<span class="dt">onZero=</span><span class="ot">TRUE</span>)) %&gt;%
<span class="st">    </span><span class="kw">setXAxis</span>(<span class="dt">axisLabel=</span><span class="kw">list</span>(
        <span class="dt">formatter=</span><span class="kw">JS</span>(<span class="st">&#39;function (value) {return Math.abs(value);}&#39;</span>)
    ))</code></pre></div>
<div id="htmlwidget-d9c03366bb16e748e9af" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-d9c03366bb16e748e9af">{"x":{"series":[{"name":"No","type":"bar","data":[-122,-167,-528,-673],"stack":"Group"},{"name":"Yes","type":"bar","data":[203,118,178,212],"stack":"Group"}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":true},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true,"formatter":"function (value) {return Math.abs(value);}"},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["xAxis.0.axisLabel.formatter","tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="bar-chart-with-timeline" class="section level3">
<h3><span class="header-section-number">3.2.6</span> Bar Chart with Timeline</h3>
<p>We need another variable as timeline. Let’s say, ‘sex’.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">titanic_sex &lt;-<span class="st"> </span>data.table::<span class="kw">melt</span>(<span class="kw">apply</span>(Titanic, <span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">4</span>), sum))
<span class="kw">names</span>(titanic_sex)[<span class="dv">4</span>] &lt;-<span class="st"> &quot;Count&quot;</span>
knitr::<span class="kw">kable</span>(titanic_sex)</code></pre></div>
<table>
<thead>
<tr class="header">
<th align="left">Class</th>
<th align="left">Sex</th>
<th align="left">Survived</th>
<th align="right">Count</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">1st</td>
<td align="left">Male</td>
<td align="left">No</td>
<td align="right">118</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">Male</td>
<td align="left">No</td>
<td align="right">154</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">Male</td>
<td align="left">No</td>
<td align="right">422</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">Male</td>
<td align="left">No</td>
<td align="right">670</td>
</tr>
<tr class="odd">
<td align="left">1st</td>
<td align="left">Female</td>
<td align="left">No</td>
<td align="right">4</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">Female</td>
<td align="left">No</td>
<td align="right">13</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">Female</td>
<td align="left">No</td>
<td align="right">106</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">Female</td>
<td align="left">No</td>
<td align="right">3</td>
</tr>
<tr class="odd">
<td align="left">1st</td>
<td align="left">Male</td>
<td align="left">Yes</td>
<td align="right">62</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">Male</td>
<td align="left">Yes</td>
<td align="right">25</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">Male</td>
<td align="left">Yes</td>
<td align="right">88</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">Male</td>
<td align="left">Yes</td>
<td align="right">192</td>
</tr>
<tr class="odd">
<td align="left">1st</td>
<td align="left">Female</td>
<td align="left">Yes</td>
<td align="right">141</td>
</tr>
<tr class="even">
<td align="left">2nd</td>
<td align="left">Female</td>
<td align="left">Yes</td>
<td align="right">93</td>
</tr>
<tr class="odd">
<td align="left">3rd</td>
<td align="left">Female</td>
<td align="left">Yes</td>
<td align="right">90</td>
</tr>
<tr class="even">
<td align="left">Crew</td>
<td align="left">Female</td>
<td align="left">Yes</td>
<td align="right">20</td>
</tr>
</tbody>
</table>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic_sex, Class, Count, Survived, <span class="dt">t=</span>Sex, <span class="dt">type=</span><span class="st">&#39;bar&#39;</span>) %&gt;%<span class="st"> </span>
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&quot;Titanic: Survival Outcome by Cabin Class Across Sex&quot;</span>)</code></pre></div>
<div id="htmlwidget-3c5639b98be68e6607ec" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-3c5639b98be68e6607ec">{"x":{"timeline":{"type":"number","data":["Male","Female"],"x":80,"x2":80,"y2":50},"options":[{"series":[{"name":"No","type":"bar","data":[118,154,422,670]},{"name":"Yes","type":"bar","data":[62,25,88,192]}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"xAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class Across Sex (Sex: Male)","x":"center","y":"bottom","orient":"horizontal"},"grid":{"y2":130}},{"series":[{"name":"No","type":"bar","data":[4,13,106,3]},{"name":"Yes","type":"bar","data":[141,93,90,20]}],"title":{"text":"Titanic: Survival Outcome by Cabin Class Across Sex (Sex: Female)","x":"center","y":"bottom","orient":"horizontal"}}]},"evals":["options.0.tooltip.formatter"],"jsHooks":[]}</script>
</div>
</div>
<div id="vertical-bar-column-chart" class="section level2">
<h2><span class="header-section-number">3.3</span> Vertical Bar (Column) Chart</h2>
<div id="tiled-vertical-bar-column-chart" class="section level3">
<h3><span class="header-section-number">3.3.1</span> Tiled Vertical Bar (Column) Chart</h3>
<p>Compared to hbar, you just set <code>type</code> ‘vbar’, or ‘column’.</p>
<p>Grammar for singular and multiple series are similar to legacy hbar chart.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic, Class, Count, Survived, <span class="dt">type=</span><span class="st">&#39;column&#39;</span>) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&#39;Titanic: Survival Outcome by Cabin Class&#39;</span>) </code></pre></div>
<div id="htmlwidget-d854a83237f5b636ba1a" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-d854a83237f5b636ba1a">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673]},{"name":"Yes","type":"bar","data":[203,118,178,212]}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</div>
<div id="stacked-vertical-bar-column-chart" class="section level3">
<h3><span class="header-section-number">3.3.2</span> Stacked Vertical Bar (Column) Chart</h3>
<p>Compared to vbar, you just set <code>subtype</code> ‘stack’.</p>
<p>Grammar for singular and multiple series are similar to legacy hbar chart.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(titanic, Class, Count, Survived, <span class="dt">type=</span><span class="st">&#39;column&#39;</span>, <span class="dt">subtype=</span><span class="st">&#39;stack&#39;</span>) %&gt;%
<span class="st">    </span><span class="kw">setTitle</span>(<span class="st">&#39;Titanic: Survival Outcome by Cabin Class&#39;</span>) </code></pre></div>
<div id="htmlwidget-f12c99b9dc872ce38947" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-f12c99b9dc872ce38947">{"x":{"series":[{"name":"No","type":"bar","data":[122,167,528,673],"stack":"Group"},{"name":"Yes","type":"bar","data":[203,118,178,212],"stack":"Group"}],"legend":{"show":true,"data":["No","Yes"],"x":"left","y":"top","orient":"horizontal"},"yAxis":[{"type":"value","show":true,"position":"left","name":"Count","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"category","show":true,"position":"bottom","name":"Class","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false},"data":["1st","2nd","3rd","Crew"]}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"formatter":"function (params) {\n       var i;\n       var j;\n       var text;\n       var text1;\n       var sName = \"\";\n       if (params.length > 1){\n            if (params[0].value.length >1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       } else {\n            if (params[0].value.length > 1) {\n                text1 = params[0].value[0];\n            } else {\n                text1 = params[0].value;\n            }\n            text = params[0].name;\n            if (params[0].seriesName) {\n                sName = params[0].seriesName;\n            }\n       }\n       if (params.length > 1){\n           text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n           for (i = 1; i < params.length; i++) {\n                if (params[i].value.length > 1){\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value[0];\n                   for (j = 1; j < params[i].value.length; j++){\n                        text += \", \" + params[i].value[j];\n                   }\n                } else {\n                   text += \"<br/>\" + params[i].seriesName + \" :  \"\n                        + params[i].value;\n                }\n           }\n       } else {\n           if (params[0].seriesName){\n               text += \"<br/>\" + params[0].seriesName + \" :  \" + text1;\n           } else {\n               text += \" :  \" + text1;\n           }\n           if (params[0].value.length > 1){\n                for (j = 1; j < params[0].value.length; j++){\n                    text += \", \" + params[0].value[j];\n                }\n           }\n       }\n       return text;\n    }","islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"title":{"text":"Titanic: Survival Outcome by Cabin Class","x":"center","y":"bottom","orient":"horizontal"}},"evals":["tooltip.formatter"],"jsHooks":[]}</script>
</div>
</div>
<div id="histogram" class="section level2">
<h2><span class="header-section-number">3.4</span> Histogram</h2>
<div id="stat-by-frequency" class="section level3">
<h3><span class="header-section-number">3.4.1</span> Stat by Frequency</h3>
<p>Histogram is a special form of bar chart, in which you only provide numeric <code>x</code> variable.</p>
<p><code>type</code> could be ‘histogram’, ‘hist’. Run <code>setTooltip(formatter='none')</code> to apply the default tooltip template in Echarts.</p>
<p>The barWidth can not be autosized in Echarts2. Please assign a suitable value yourself.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(iris, Sepal.Width, <span class="dt">width=</span><span class="dv">600</span>) %&gt;%
<span class="st">   </span><span class="kw">setTitle</span>(<span class="st">&#39;Iris: Histogram of Sepal.Width&#39;</span>) %&gt;%
<span class="st">   </span><span class="kw">setTooltip</span>(<span class="dt">formatter=</span><span class="st">&#39;none&#39;</span>) %&gt;%<span class="st"> </span><span class="kw">setSeries</span>(<span class="dv">1</span>, <span class="dt">barWidth=</span><span class="dv">500</span>/<span class="dv">13</span>)</code></pre></div>
<div id="htmlwidget-fa3e0c2ecfb5b1121faa" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-fa3e0c2ecfb5b1121faa">{"x":{"series":[{"type":"bar","data":[[2.1,4],[2.3,7],[2.5,13],[2.7,23],[2.9,36],[3.1,24],[3.3,18],[3.5,10],[3.7,9],[3.9,3],[4.1,2],[4.3,1]],"barGap":"1%","barMaxWidth":63,"barWidth":38.4615384615385}],"yAxis":[{"type":"value","show":true,"position":"left","name":"Freq","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"value","show":true,"position":"bottom","name":"Sepal.Width","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"legend":{"show":true,"data":[],"x":"left","y":"top","orient":"horizontal"},"title":{"text":"Iris: Histogram of Sepal.Width","x":"center","y":"bottom","orient":"horizontal"}},"evals":[],"jsHooks":[]}</script>
</div>
<div id="stat-by-density" class="section level3">
<h3><span class="header-section-number">3.4.2</span> Stat by Density</h3>
<p>Sometimes you want a density historam, then set <code>subtype</code> ‘density’.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">echartr</span>(iris, Sepal.Width, <span class="dt">type=</span><span class="st">&#39;hist&#39;</span>, <span class="dt">subtype=</span><span class="st">&#39;density&#39;</span>, <span class="dt">width=</span><span class="dv">600</span>) %&gt;%
<span class="st">  </span><span class="kw">setTitle</span>(<span class="st">&#39;Iris: Histogram of Sepal.Width&#39;</span>) %&gt;%<span class="st"> </span><span class="kw">setYAxis</span>(<span class="dt">name=</span><span class="st">&quot;Density&quot;</span>) %&gt;%
<span class="st">  </span><span class="kw">setTooltip</span>(<span class="dt">formatter=</span><span class="st">&#39;none&#39;</span>) %&gt;%<span class="st"> </span><span class="kw">setSeries</span>(<span class="dv">1</span>, <span class="dt">barWidth=</span><span class="dv">500</span>/<span class="dv">13</span>)</code></pre></div>
<div id="htmlwidget-f58539d0ad4ac64faca1" style="width:672px;height:480px;" class="echarts html-widget"></div>
<script type="application/json" data-for="htmlwidget-f58539d0ad4ac64faca1">{"x":{"series":[{"type":"bar","data":[[2.1,0.133333333333333],[2.3,0.233333333333334],[2.5,0.433333333333333],[2.7,0.766666666666666],[2.9,1.2],[3.1,0.799999999999999],[3.3,0.599999999999999],[3.5,0.333333333333333],[3.7,0.3],[3.9,0.1],[4.1,0.0666666666666663],[4.3,0.0333333333333335]],"barGap":"1%","barMaxWidth":63,"barWidth":38.4615384615385}],"yAxis":[{"type":"value","show":true,"position":"left","name":"Density","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"xAxis":[{"type":"value","show":true,"position":"bottom","name":"Sepal.Width","nameLocation":"end","boundaryGap":[0,0],"scale":true,"axisLine":{"show":true,"onZero":false},"axisTick":{"show":false},"axisLabel":{"show":true},"splitLine":{"show":true},"splitArea":{"show":false}}],"tooltip":{"show":true,"trigger":"axis","axisPointer":{"type":"shadow","crossStyle":{"type":"dashed"},"lineStyle":{"type":"solid","width":1},"shadowStyle":{"color":"rgba(150,150,150,0.3)","width":"auto","type":"default"}},"textStyle":{"color":"#fff"},"islandFormatter":"{a} < br/>{b} : {c}","enterable":false,"showDelay":20,"hideDelay":100,"transitionDuration":0.4,"backgroundColor":"rgba(0,0,0,0.7)","borderColor":"#333","borderWidth":0,"borderRadius":4},"toolbox":{"show":true,"feature":{"mark":{"show":true},"dataZoom":{"show":true},"dataView":{"show":true,"readOnly":false},"magicType":{"show":true,"type":["line","bar","tiled","stack"]},"restore":{"show":true},"saveAsImage":{"show":true}},"x":"right","y":"top","orient":"horizontal"},"legend":{"show":true,"data":[],"x":"left","y":"top","orient":"horizontal"},"title":{"text":"Iris: Histogram of Sepal.Width","x":"center","y":"bottom","orient":"horizontal"}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</div>
<div id="futher-setup" class="section level1">
<h1><span class="header-section-number">4</span> Futher Setup</h1>
<p>Then you can configure the widgets, add markLines and/or markPoints, fortify the chart.</p>
<hr />
<p>You can refer to related functions to play around on your own.</p>
</div>

<script type="text/javascript">
window.onload = function() {
  var i, fig = 1, caps = document.getElementsByClassName('caption');
  for (i = 0; i < caps.length; i++) {
    var cap = caps[i];
    if (cap.parentElement.className !== 'figure' || cap.nodeName !== 'P')
      continue;
    cap.innerHTML = '<span>Figure ' + fig + ':</span> ' + cap.innerHTML;
    fig++;
  }
  fig = 1;
  caps = document.getElementsByTagName('caption');
  for (i = 0; i < caps.length; i++) {
    var cap = caps[i];
    if (cap.parentElement.nodeName !== 'TABLE') continue;
    cap.innerHTML = '<span>Table ' + fig + ':</span> ' + cap.innerHTML;
    fig++;
  }
}
</script>



</div>

<script>

// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
  $('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
  bootstrapStylePandocTables();
});


</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
